package com.airsystem.pos.bengkel.model.dialog;

import java.awt.GridBagLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import com.airsystem.pos.bengkel.component.DialogFrame;
import com.airsystem.pos.bengkel.entity.Tagihan;
import com.airsystem.pos.bengkel.entity.wrapper.TagihanWrapper;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class MasterBillingDetailDialogModel extends DialogFrame {
	protected int row = 0;

	private static final String[] COLUMNS = { "Periode", "Total" };

	protected static final String[] COMBOMENU = { "Periode" };

	protected final GridBagLayout baseLayout = new GridBagLayout();
	protected final GridBagLayout tableLayout = new GridBagLayout();

	protected final JPanel basePanel = new JPanel();
	protected final JPanel tablePanel = new JPanel();

	protected final JScrollPane tableScroll = new JScrollPane();

	protected final JTable tableData = new JTable();

	protected final JLabel searchLabel = new JLabel();

	protected final JComboBox searchCombo = new JComboBox();

	protected final JTextField searchField = new JTextField();

	protected final JButton searchButton = new JButton();

	protected final DefaultTableModel tableModel = new DefaultTableModel(new Object[][] {}, COLUMNS) {
		final boolean[] canEdit = new boolean[] { false, false };

		public boolean isCellEditable(int rowIndex, int columnIndex) {
			return canEdit[columnIndex];
		}
	};

	private Tagihan tagihan;

	protected TagihanWrapper tagihanRow;

	public Tagihan getDetailSparepart() {
		return tagihan;
	}

	public void setTagihan(Tagihan tagihan) {
		this.tagihan = tagihan;
	}

	protected Tagihan getComponentData() {
		Tagihan tagihan = new Tagihan();

		return tagihan;
	}

	protected Tagihan getSearchData() {
		Tagihan tagihan = new Tagihan();
		tagihan.setChoice(searchCombo.getSelectedIndex());

		String input = searchField.getText().trim();

		switch (tagihan.getChoice()) {
		case PERIODE: {
			tagihan.setPeriode(input);
			break;
		}

		default: {
			throw new IllegalArgumentException("Wrong chosen search combo");
		}
		}

		return tagihan;
	}

	public TagihanWrapper getTagihanRow() {
		return tagihanRow;
	}
}